package com.ruoyi.web.controller.depot;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.depot.domain.LocalInventoryReservedLog;
import com.ruoyi.depot.domain.vo.LocalInventoryVO;
import com.ruoyi.depot.service.ILocalInventoryReservedLogService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.depot.domain.LocalInventory;
import com.ruoyi.depot.service.ILocalInventoryService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 库存Controller
 * 
 * @author luxiaoyu
 * @date 2024-12-19
 */
@RestController
@RequestMapping("/depot/localInventory")
public class LocalInventoryController extends BaseController
{
    @Autowired
    private ILocalInventoryService localInventoryService;

    @Autowired
    private ILocalInventoryReservedLogService iLocalInventoryReservedLogService;

    /**
     * 查询库存列表
     */
    @PreAuthorize("@ss.hasPermi('depot:localInventory:list')")
    @GetMapping("/list")
    public TableDataInfo list(LocalInventory localInventory)
    {
        startPage();
        List<LocalInventoryVO> list = localInventoryService.selectLocalInventoryList(localInventory);
        return getDataTable(list);
    }

    /**
     * 导出库存列表
     */
    @PreAuthorize("@ss.hasPermi('depot:localInventory:export')")
    @Log(title = "库存", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LocalInventory localInventory)
    {
        List<LocalInventoryVO> list = localInventoryService.selectLocalInventoryList(localInventory);
        ExcelUtil<LocalInventoryVO> util = new ExcelUtil<LocalInventoryVO>(LocalInventoryVO.class);
        util.exportExcel(response, list, "库存数据");
    }

    /**
     * 获取库存详细信息
     */
    @PreAuthorize("@ss.hasPermi('depot:localInventory:query')")
    @GetMapping(value = "/{inventoryId}")
    public AjaxResult getInfo(@PathVariable("inventoryId") String inventoryId)
    {
        return success(localInventoryService.selectLocalInventoryByInventoryId(inventoryId));
    }

    /**
     * 新增库存
     */
    @PreAuthorize("@ss.hasPermi('depot:localInventory:add')")
    @Log(title = "库存", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LocalInventory localInventory)
    {
        return toAjax(localInventoryService.insertLocalInventory(localInventory));
    }

    /**
     * 修改库存
     */
    @PreAuthorize("@ss.hasPermi('depot:localInventory:edit')")
    @Log(title = "库存", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LocalInventory localInventory)
    {
        return toAjax(localInventoryService.updateLocalInventory(localInventory));
    }

    /**
     * 删除库存
     */
    @PreAuthorize("@ss.hasPermi('depot:localInventory:remove')")
    @Log(title = "库存", businessType = BusinessType.DELETE)
	@DeleteMapping("/{inventoryIds}")
    public AjaxResult remove(@PathVariable Long[] inventoryIds)
    {
        return toAjax(localInventoryService.deleteLocalInventoryByInventoryIds(inventoryIds));
    }

    /**
     * 修改预定量/锁定量
     */
    @PreAuthorize("@ss.hasPermi('depot:localInventory:rqEdit')")
    @Log(title = "库存", businessType = BusinessType.UPDATE)
    @PutMapping("/updateReservedQuantity")
    public AjaxResult updateReservedQuantity(@RequestBody LocalInventory localInventory)
    {
        return toAjax(localInventoryService.updateReservedQuantity(localInventory));
    }
    /**
     * 查询预定量/锁定量变动记录
     */
    @PreAuthorize("@ss.hasPermi('depot:localInventory:rqEdit')")
    @GetMapping("/listReservedQuantityLog")
    public TableDataInfo listReservedQuantityLog(LocalInventoryReservedLog inventoryReservedLog)
    {
        startPage();
        List<LocalInventoryReservedLog> list = iLocalInventoryReservedLogService.listReservedQuantityLog(inventoryReservedLog);
        return getDataTable(list);
    }
}
